package com.example.dbdoc.enums;

/**
 * 数据库类型枚举
 * 
 * @author 系统生成
 * @version 1.0.0
 */
public enum DatabaseType {
    MYSQL("MySQL", "com.mysql.cj.jdbc.Driver", "com.mysql.jdbc.Driver"),
    POSTGRESQL("PostgreSQL", "org.postgresql.Driver");
    
    private final String displayName;
    private final String[] driverClassNames;
    
    DatabaseType(String displayName, String... driverClassNames) {
        this.displayName = displayName;
        this.driverClassNames = driverClassNames;
    }
    
    public String getDisplayName() {
        return displayName;
    }
    
    public String[] getDriverClassNames() {
        return driverClassNames;
    }
    
    /**
     * 根据驱动类名判断数据库类型
     */
    public static DatabaseType fromDriverClassName(String driverClassName) {
        if (driverClassName == null) {
            return MYSQL; // 默认MySQL
        }
        
        for (DatabaseType type : values()) {
            for (String driver : type.driverClassNames) {
                if (driver.equals(driverClassName)) {
                    return type;
                }
            }
        }
        
        return MYSQL; // 默认MySQL
    }
    
    /**
     * 根据JDBC URL判断数据库类型
     */
    public static DatabaseType fromUrl(String url) {
        if (url == null) {
            return MYSQL;
        }
        
        if (url.startsWith("jdbc:postgresql:")) {
            return POSTGRESQL;
        } else if (url.startsWith("jdbc:mysql:")) {
            return MYSQL;
        }
        
        return MYSQL; // 默认MySQL
    }
}
